package com.znz.analysis.main;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 获得单例ClassPathXmlApplicationContext
 * 
 * @author TP
 * @version 创建时间：2017年6月26日 下午5:14:48
 */
public class ApplicationContextFactory {
	// Singleton
	private volatile static ClassPathXmlApplicationContext context;

	private ApplicationContextFactory() {
	}

	/**
	 * 获取单例对象
	 * 
	 * @return
	 */
	public static ClassPathXmlApplicationContext getInstance() {
		// double check
		if (context == null) {
			synchronized (ApplicationContextFactory.class) {
				if (context == null) {
					context = new ClassPathXmlApplicationContext("classpath*:/application.xml");
					System.out.println("Init ClassPathXmlApplicationContext successfully");
				}
			}
		}
		return context;
	}

}
